<?php

/**
 * メンバーに関して全てのデータを取得する
 * 
 * create:　2012-02-25
 * update:　2012-02-27
 * create: ツバサ(エスワイシステム)
 * */
class MemberResumeController extends AppController {
	
	var $name = null;
	
	var $uses = array(
		'Member', 'MemberResume', 'MemberEducation', 'MemberWork', 'Order', 
		'MemberExpWorktype', 'Company', 'CompanyAccount', 'SysParams', 'MailJob',
		'Job', 'News', 'JobHopeMember', 'JobHopeLanguage',
		'JobCategory', 'JobAttention', 'JobArea', 'JobPost', 'JobPickupArea',
		'JobPickupThema', 'JobAttentionArea', 'JobAttentionThema','WebMsgInfo','ScoutMsgReactionInfo'
		,'SpecialPublicInfo'
	);
	
	/**
	 * モデルMemberResume、MemberEducation、MemberExpWorktype、MemberWorkから
	 *　データを取得する
	 *
	 * create: 2012-02-24
	 * update:
	 * create: ツバサ(エスワイシステム)
	 * */
	protected function getResumeData($id) {
		//職務経歴情報を取得する	ツバサ(エスワイシステム) 2012-02-23
		$resume = $this->MemberResume->find(
			"\"MemberResume\".member_id=" . $id . " and \"MemberResume\".deleted is null");
		$this->setIncome($resume['MemberResume']['now_income'], $resume['MemberResume']['now_income_cur'],'','now_income');
		//学歴情報を取得する	ツバサ(エスワイシステム) 2012-02-23
		$edu = $this->MemberEducation->findAll(
			"\"MemberEducation\".member_id=" . $id . " and \"MemberEducation\".deleted is null", 
			null, "MemberEducation.id");
		$this->eduTime($edu);
		//職務経歴情報を取得する	ツバサ(エスワイシステム) 2012-02-23
		$work = $this->MemberWork->findAll(
			"\"MemberWork\".member_id=" . $id . " and \"MemberWork\".deleted is null", 
			null, "MemberWork.id");
		$this->workTime($work);
		//会員経験職種情報を取得する	ツバサ(エスワイシステム) 2012-02-23
		$expworktype = $this->MemberExpWorktype->findAll(
			"\"MemberExpWorktype\".member_id=" . $id . " and \"MemberExpWorktype\".deleted is null", 
			null, "MemberExpWorktype.id");
		return array(
			'resume'=>$resume, 'edu'=>$edu, 'work'=>$work, 
			'expworktype'=>$expworktype 
		);
	}
	
	/**
	 * member_infoから取得した留学経験、外国勤務経験、語学レベル
	 * 希望勤務地、希望職業のデータによって、配列を作成する
	 * 
	 * create:ツバサ(エスワイシステム)
	 * update:
	 * */
	protected function memberExpToArray(&$member) {
		$member['edu'] = array();
		$key = 'SysParams';
		//留学経験
		$pointer = 26;
		for($i = $pointer; $i < $pointer + 9; $i+=3) {
			$temp = array();
			$temp['nation'] = $member[$key.($i)]['name'];
			$temp['period'] = $member[$key.($i+1)]['name'];
			$temp['purpose'] = $member[$key.($i+2)]['name'];
			if($temp['nation'] || $temp['period'] || $temp['purpose']) {
				array_push($member['edu'], $temp);
			}
		}
		//外国での勤務経験
		$pointer = 35;
		$member['work'] = array();
		for($i = $pointer; $i < $pointer + 9; $i+=3) {
			$temp = array();
			$temp['nation'] = $member[$key.($i)]['name'];
			$temp['period'] = $member[$key.($i+1)]['name'];
			$temp['purpose'] = $member[$key.($i+2)]['name'];
			if($temp['nation'] || $temp['period'] || $temp['purpose']) {
				array_push($member['work'], $temp);
			}
		}
		
		//@author wang.wei 2012/3/19 add start
		//語学レベル
		$pointer = 62;
		$member['language'] = array();
		for($i = $pointer; $i < $pointer + 10; $i+=2) {
			$temp = array();
			$temp['lang'] = $member[$key.($i)]['name'];
			$temp['level'] = $member[$key.($i+1)]['name'];
			if($temp['lang'] || $temp['level']) {
				array_push($member['language'], $temp);
			}
		}
		//@author wang.wei 2012/3/19 add end
		/* //語学レベル
		$pointer = 44;
		$member['language'] = array();
		for($i = $pointer; $i < $pointer + 6; $i+=2) {
			$temp = array();
			$temp['lang'] = $member[$key.($i)]['name'];
			$temp['level'] = $member[$key.($i+1)]['name'];
			if($temp['lang'] || $temp['level']) {
				array_push($member['language'], $temp);
			}
		} */
		
// 		希望業種、職種
		$pointer = 52;
		$member['hope_work'] = array();
		for($i = $pointer; $i < $pointer + 9; $i+=3) {
			$temp = array();
			$temp['category'] = $member[$key.($i)]['name'];
			$temp['big'] = $member[$key.($i+1)]['name'];
			$temp['small'] = $member[$key.($i+2)]['name'];
			if($temp['category'] || $temp['big'] || $temp['small']) {
				array_push($member['hope_work'], $temp);
			}
		}
		
		//希望業種
		$pointer = 52;
		$member['hope_category'] = array();
		for($i = $pointer; $i < $pointer + 9; $i+=3) {
			$temp = array();
			$temp = $member[$key.($i)]['name'];
			if($temp != null) {
				array_push($member['hope_category'], $temp);
			}
		}
		
// 		希望職種
		$pointer = 52;
		$member['hope_worktype'] = array();
		for($i = $pointer; $i < $pointer + 9; $i+=3) {
			$temp = array();
			$temp['big'] = $member[$key.($i+1)]['name'];
			$temp['small'] = $member[$key.($i+2)]['name'];
			if($temp['big'] != null || $temp['small'] != null) {
				array_push($member['hope_worktype'], $temp);
			}
		}
		
		//希望勤務地
		$pointer = 23;
		$member['hope_location'] = array();
		for($i = $pointer; $i < $pointer + 3; $i++) {
			$temp = $member[$key.$i]['name'];
			if($temp != null) {
				array_push($member['hope_location'], $temp);
			}
		}
	}
	
	/**
	 * テーブルmember_work_infoの
	 * exp_work_start_year、exp_work_start_month、
	 * exp_work_end_year、exp_work_end_monthによる
	 * 書式した勤務期間を返す
	 *
	 * create: 2012-02-23
	 * update:　2012-03-13
	 * create: ツバサ(エスワイシステム)
	 * */
	protected function workTime(&$work) {
		for($i = 0; $i < count($work); $i++) {
			$workTime = null;
			$startYear = $work[$i]['MemberWork']['exp_work_start_year'];
			$startMonth = $work[$i]['MemberWork']['exp_work_start_month'];
			$endYear = $work[$i]['MemberWork']['exp_work_end_year'];
			$endMonth = $work[$i]['MemberWork']['exp_work_end_month'];
			$workTime .= $startYear.'年'.$startMonth.'月';
			$workTime .= ' ～ ';
			if($work[$i]['MemberWork']['exp_work_flg'] == 0) {
				$workTime .= '在籍中';
			} else {
				$workTime .= $endYear.'年'.$endMonth.'月';
			}
			if (empty($startYear) && empty($startMonth) && empty($endYear) && empty($endMonth)) { 
				$workTime = null;
			}
			$work[$i]['MemberWork']['work_time'] = $workTime;
		}
	}
	
	/**
	 * 書式した学歴在籍情報
	 * 
	 * create: 2012-03-13 ツバサ(エスワイシステム)
	 * update:　
	 * */
	private function eduTime(&$edu) {
		for ($i = 0; $i<count($edu) ;$i++) {
			if($edu[$i]['MemberEducation']['edu_start'] != null) {
				$edu[$i]['MemberEducation']['edu_start'] =
						date('Y年n月', strtotime($edu[$i]['MemberEducation']['edu_start']));
			}
			if($edu[$i]['MemberEducation']['edu_end'] != null) {
				$edu[$i]['MemberEducation']['edu_end'] =
						date('Y年n月', strtotime($edu[$i]['MemberEducation']['edu_end']));
			}			
		}
	}
	
	/**
	 * 説明不要
	 *
	 *
	 * create: 2012-03-13 ツバサ(エスワイシステム)
	 * update:
	 * */
	private function nvl($var, $nilVar = '?') {
		if($var == null) {
			return $nilVar;
		} else {
			return $var;
		}
	}
	
	/**
	 * テーブルmember_infoのhope_income_flg、hope_income_cur、hope_incomeによる
	 * 書式した年収
	 *
	 * create: 2012-02-22
	 * update:
	 * create: ツバサ(エスワイシステム)
	 * */
	protected function setIncome(&$money, $cur, $money_to, $type) {
		$cur = $this->SysParams->find("\"SysParams\".id=".$cur.
				" and \"SysParams\".kbn = 'income_cur'", 'name');
		/* wang.wei 2012/12/10 update start */
		if(!empty($money) && empty($money_to)){
			$money = number_format($money)." ".$cur['SysParams']['name'];
			if($type == 'hope_income'){
				$money .= '以上';
			}
		}
		else if(!empty($money_to) && empty($money)){
			$money = number_format($money_to)." ".$cur['SysParams']['name'].'以下';
		}else if(!empty($money_to) && !empty($money)){
			$money = number_format($money)." ～ ".number_format($money_to)." ".$cur['SysParams']['name'];
		}
		// wang.wei update 2012/3/16
		//$money = $money != '' ? number_format($money).' '.$cur['SysParams']['name']: null;
		/* wang.wei 2012/12/10 update end */
	}
	
	/**
	 * テーブルmember_infoのwork_visa_flg、work_visa_nationによる
	 * 書式した就労ビザを返す
	 *
	 * create: 2012-02-22
	 * update:
	 * create: ツバサ(エスワイシステム)
	 * */
	protected function setWorkVisa($mem) {
		if ($mem['Member']['work_visa_flg'] == 0 && $mem['SysParams51']['name']) { //就労ビザを持ってる場合
			return $mem['SysParams51']['name'];
		}
		return '無し';
	}
	
	/**
	 * テーブルmember_infoのpublic_profile_flgから
	 * もらった数字情報を文字列に換える
	 *
	 * create: 2012-02-22
	 * update:
	 * create: ツバサ(エスワイシステム)
	 * */
	protected function setPublicProfileFlg($publicProfileFlgId) {
		switch($publicProfileFlgId) {
			case 1:
				return $this->Prop->getValue('config.Scout/Company');
			case 2:
				return $this->Prop->getValue('config.Scout/All');
			case 3:
				return $this->Prop->getValue('config.Scout/No');
			default:
				return null;
		}
	}
	
	/**
	 * ディバッグ用メソッド
	 *
	 * create: 2012-03-05 ツバサ(エスワイシステム)
	 * */
	protected function debug_println($str) {
		if($this->Prop->getValue('config.debug')) {
			if(is_array($str)) {
				print_r($str);
			} else {
				echo $str;
			}
			echo '<br>';
		}
	}

}

?>